Add support for JUnit6#1659
Conversation
|
Part 1 and Part 2 are almost identical. Only the following three things should be different:
|
25a25d8 to
c9660f2
Compare
9998433 to
dabea23
Compare
| Stream<T> FrozenRulesTest(Class<?> frozenRulesTestClass) { | ||
| return frozenRulesExpectedTestFailures(frozenRulesTestClass).toDynamicTests(); | ||
| } |
There was a problem hiding this comment.
no aroundTestInvoke is needed for JUnit6 - it was only needed on Java 8 and 11, which JUnit6 doesn't support
| def addCleanThirdPartyTask = { | ||
| // These files are already relocated into archunit.jar, so they're transitively available | ||
| tasks.create(name: 'removeDuplicateThirdParty', type: Jar, dependsOn: shadowJar) { | ||
| exclude "${thirdPartyRelocationPackage.replace('.', '/')}/**" | ||
|
|
||
| File tempPath = tempJar(jar.archiveFile.get().getAsFile()) | ||
| File jarPath = shadowJar.archiveFile.get().getAsFile() | ||
| inputs.file(jarPath) | ||
| from zipTree(jarPath) | ||
| archiveFileName = tempPath.name | ||
|
|
||
| doLast { | ||
| assert jarPath.delete() | ||
| assert tempPath.renameTo(jarPath) | ||
| } | ||
| } | ||
| finishArchive.dependsOn removeDuplicateThirdParty | ||
| } |
There was a problem hiding this comment.
This task caused build failures on Windows. After some investigation, I concluded that it is no longer needed - the existing dependencies.exclude() make this transformation an identity operation. Also, there is test coverage for missing exclude statements (see :checkArtifact), so we can't accidentally publish a release where the problem that this code meant to address is present.
| Set<SingleTest> result = new HashSet<>(); | ||
| for (int i = 0; i < classNames.size(); i++) { | ||
| result.add(new SingleTest(classNames.get(i), testNames.get(i))); | ||
| result.add(new SingleTest(toSimpleClassName(classNames.get(i)), testNames.get(i))); |
There was a problem hiding this comment.
This was needed due to a change in the test reports (major version upgrade)
There was a problem hiding this comment.
Which should be isolated in a separate commit, as it's entirely unrelated to Add JUnit6 test coverage. 😉
There was a problem hiding this comment.
Fair enough. It is a necessary prerequisite since the old version of Surefire didn't work with JUnit 6.
| [prepareMavenTest, executeRules, verifyRules, cleanUpMavenTest, runMavenTest].each { taskName -> | ||
| tasks[taskName].onlyIf("requires Java ${config.minimumJavaVersion} or higher") { | ||
| config.supports(integrationTestJavaVersion) | ||
| } | ||
| } |
There was a problem hiding this comment.
We cannot run the JUnit6 tasks on Java 8 and 11, hence this new block
| .replace('#{mavenSurefirePluginVersion}', "${mavenSurefirePlugin.version}") | ||
| .replace('#{mavenCompilerPluginVersion}', "${mavenCompilerPlugin.version}") |
There was a problem hiding this comment.
This way, the plugins are updated via dependabot
| surefireExampleConfiguration: '<groups>example</groups>', | ||
| archunitTestArtifact: 'archunit-junit5', | ||
| additionalDependencies: """ | ||
| def testConfigFor = (TestType testType) -> { |
There was a problem hiding this comment.
This restructure makes it harder to forget adding a case for a new JUnit version
| public static class ArchUnitProductionCode implements ImportOption { | ||
| private static final Set<String> SOURCE_ROOTS = sourceRootsOf( | ||
| ArchConfiguration.class, | ||
| ArchUnitRunner.class, | ||
| ArchTag.class, | ||
| FieldSelector.class, | ||
| ArchUnitTestEngine.class); | ||
|
|
||
| private static Set<String> sourceRootsOf(Class<?>... classes) { | ||
| ImmutableSet.Builder<String> result = ImmutableSet.builder(); | ||
| for (Class<?> c : classes) { | ||
| String classFile = "/" + c.getName().replace('.', '/') + ".class"; | ||
| String file = c.getResource(classFile).getFile(); | ||
| result.add(file.substring(0, file.indexOf(classFile))); | ||
| } | ||
| return result.build(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean includes(Location location) { | ||
| boolean include = false; | ||
| for (String sourceRoot : SOURCE_ROOTS) { | ||
| if (location.contains(sourceRoot)) { | ||
| include = true; | ||
| } | ||
| } | ||
| return include && DO_NOT_INCLUDE_TESTS.includes(location); | ||
| } | ||
| } |
There was a problem hiding this comment.
We now decide on a subproject basis if something is "production code"
There was a problem hiding this comment.
moved to archunit-self-test/src/main/java/com/tngtech/archunit/ArchUnitExampleArchitectureRules.java with too many changes
| implementation project(path: ':archunit') | ||
| implementation project(path: ':archunit-junit4') | ||
| implementation project(path: ':archunit-junit5') | ||
| implementation project(path: ':archunit-junit5-engine') | ||
| implementation project(path: ':archunit-example:example-plain') | ||
| implementation project(path: ':archunit-example:example-plain', configuration: 'tests') | ||
| implementation project(path: ':archunit-example:example-junit4', configuration: 'tests') | ||
| implementation project(path: ':archunit-example:example-junit5', configuration: 'tests') | ||
|
|
||
| testImplementation project(path: ':archunit-junit5') |
There was a problem hiding this comment.
The self-tests are now imported by those packages. This was necessary because classes between archunit-junit5 and archunit-junit6 would collide, and only one of them would get tested
| @@ -0,0 +1,29 @@ | |||
| sourceSets { | |||
| archTest { | |||
There was a problem hiding this comment.
We use a separate source set because the self-tests need a specific archunit-junit* version, which would otherwise pollute the test classpath or interfere with other tests
Issue: #1556 Signed-off-by: junya koyama <arukiidou@yahoo.co.jp>
Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
- Required because the previous setting was unable to test junit5-engine and junit6-engine at the same time Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
This task caused build failures on Windows. After some investigation, I concluded that it is no longer needed - the existing `dependencies.exclude()` make this transformation an identity operation. Also, there is test coverage for missing `exclude` statements (see `:checkArtifact`), so we can't accidentally publish a release where the problem that this code meant to address is present. Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
dabea23 to
75512aa
Compare
| @@ -20,13 +20,12 @@ task ensureReleaseCheckUpToDate { | |||
| VersionCatalog versionCatalog = versionCatalogs.named("libs") | |||
| def dependencies = versionCatalog.libraryAliases.collect { versionCatalog.findLibrary(it).get().get() } | |||
| def matchingProjectDependency = dependencies.find { | |||
There was a problem hiding this comment.
The old logic no longer worked on dependencies to junit-platform-launcher which would get mixed up
Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
| def junit5VintageEngine = libs.junit5VintageEngine.get() | ||
| def junit6VintageEngine = libs.junit6VintageEngine.get() |
There was a problem hiding this comment.
Those could be moved to the case TestType.JUNIT5 / JUNIT6 blocks.
| Set<SingleTest> result = new HashSet<>(); | ||
| for (int i = 0; i < classNames.size(); i++) { | ||
| result.add(new SingleTest(classNames.get(i), testNames.get(i))); | ||
| result.add(new SingleTest(toSimpleClassName(classNames.get(i)), testNames.get(i))); |
There was a problem hiding this comment.
Which should be isolated in a separate commit, as it's entirely unrelated to Add JUnit6 test coverage. 😉
| testImplementation project(path: ':archunit-example:example-junit6', configuration: 'tests') | ||
|
|
||
| testRuntimeOnly project(path: ':archunit-junit6-engine') | ||
| // TODO still up-to-date? |
… be allow-listed Signed-off-by: Dr. Jonathan Schulz <jonathan.schulz@tngtech.com>
Uh oh!
There was an error while loading. Please reload this page.